define(['config','barcode','printArea'],function(config,viewHTML,barcode,printArea){


    function contactItem(data) {
              //avalon.log(data);
                this.id = data.id;
                this.sender_company = data.sender_company;
                this.sender_address = data.sender_address;
                this.sender_phone = data.sender_phone;
                this.recipient_name = data.recipient_name;
                this.recipient_address = data.recipient_address;
                this.recipient_phone = data.recipient_phone;
                this.pcs = data.pcs;
                this.wt = data.wt;
                this.tracking = data.tracking;

    }

    var model = avalon.define({
    	       $id: "PrintPanel",
             contactlists: [],
             tracking:"",
               initform: function() {
                   

                    $.ajax("http://127.0.0.1:8888/services/sheets/list", {

                    type: "GET",
         
                    xhrFields: {

                      withCredentials: true,
                      useDefaultXhrHeader: false
                    },

                    crossDomain: true,

                    success: function(data, status, xhr) {
                       //avalon.log(data);
                     var contactLists = $.map(data, function (item) {
                        model.tracking = item.tracking;
                        return new contactItem(item)
                     });
                     model.contactlists.pushArray(contactLists);

                    
                     
                    },
                    error: function (responseData, textStatus, errorThrown) {
                          alert("Failed: "+responseData);
                      }
                
                  });
               },
               print:function(){

                  var mode = $("input#popup").is(":checked") ? "popup" : "iframe";
                  var close = false;
                  var extraCss = "";

                  var keepAttr = [];
                  

                  var headElements = '';
                  var ht = 500;
                  var wd = 800;

                  var options = { mode : mode, popClose : close, popHt: ht, popWd: wd,extraCss : extraCss, retainAttr : keepAttr, extraHead : headElements };

                  $("div.pager").printArea( options );

               },
               printview:function(){
                  preview();

               }
 

    });

    model.initform();

     //监听当前的菜单，切换对应的视图
    model.$watch('tracking',function(newval,oldval){
           avalon.log(newval);

           
    });


    require(['jquery','domReady!'], function($) {
        //avalon.log('加载完了啊……');
        //$(".ccode").barcode('5312015111130',"code128",{barWidth:"2",barHeight:"70",fontSize:"22"});
        $(".barcode").each(function(){
            $(this).barcode($(this).html(),"code128",{barWidth:"2",barHeight:"70",fontSize:"22"}); 
        });

        
    })

    
    

   return model;
});